<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>轮播图带缩略图</title>
    <style>
        html,
        body,
        div,
        img,
        span,
        ul,
        li {
            margin: 0;
            padding: 0;
        }
        
        html {
            width: 100%;
            height: 100%;
            background-color: #000;
        }
        
        ul {
            width: 85px;
            margin: 20px auto 0;
        }
        
        li {
            position: relative;
            float: left;
            margin-left: 15px;
            list-style-type: none;
        }
        
        li div {
            border-radius: 5px;
            width: 10px;
            height: 10px;
            background-color: #CAC6C6;
            cursor: pointer;
        }
        
        li:first-child {
            margin-left: 0;
        }
        
        li img {
            display: none;
            position: absolute;
            left: -45px;
            top: 30px;
            border: 5px solid #fff;
            width: 100px;
            height: 150px;
        }
        
        .triangle {
            display: none;
            position: absolute;
            left: 0;
            top: 20px;
            width: 0;
            height: 0;
            border-right: 5px solid transparent;
            border-bottom: 10px solid #fff;
            border-left: 5px solid transparent;
        }
        
        .checked {
            background-color: #B3860A;
        }
        
        #wrapper {
            position: absolute;
            left: 50%;
            top: 40%;
            transform: translate(-50%, -50%);
        }
        
        .arrow {
            border: 1px solid #f4f4f4;
            width: 20px;
            height: 20px;
            font-size: 20px;
            line-height: 20px;
            color: #fff;
            text-align: center;
            cursor: pointer;
        }
        
        #prev {
            position: absolute;
            left: 10%;
            top: 50%;
            transform: translate(-50%, -50%);
        }
        
        #next {
            position: absolute;
            right: 10%;
            top: 50%;
            transform: translate(50%, -50%);
        }
        
        #image {
            width: 400px;
            height: 600px;
        }
    </style>
</head>

<body>
    <div id="wrapper">
        <img id="image" src="./img/1.png" alt="">
        <span id="prev" class="arrow"><</span>
        <span id="next" class="arrow">></span>
        <ul id="imgList">
            <li>
                <div class="checked"></div>
                <img src="./img/1.png" alt="">
                <span class="triangle"></span>
            </li>
            <li>
                <div></div>
                <img src="./img/2.png" alt="">
                <span class="triangle"></span>
            </li>
            <li>
                <div></div>
                <img src="./img/3.png" alt="">
                <span class="triangle"></span>
            </li>
            <li>
                <div></div>
                <img src="./img/4.png" alt="">
                <span class="triangle"></span>
            </li>
        </ul>
    </div>

    <script>
        var i = 0;
        var imgList = ['./img/1.png', './img/2.png', './img/3.png', './img/4.png'];
        var oUl = document.getElementById('imgList');
        var oImg = document.getElementById('image');
        var oDivs = oUl.getElementsByTagName('div');
        var oImgs = oUl.getElementsByTagName('img');
        var oSpans = oUl.getElementsByTagName('span');
        document.getElementById('prev').onclick = function() {
            oDivs[i].className = '';
            if (i == 0) {
                i = 3;
            } else {
                i--;
            }
            oImg.src = imgList[i];
            oDivs[i].className = 'checked';
        }

        document.getElementById('next').onclick = function() {
            oDivs[i].className = '';
            if (i == 3) {
                i = 0;
            } else {
                i++;
            }
            oImg.src = imgList[i];
            oDivs[i].className = 'checked';
        }

        for (var j = 0; j < oDivs.length; j++) {
            oDivs[j].index = j;
            oDivs[j].onmouseenter = function() {
                oImgs[this.index].style.display = 'block';
                oSpans[this.index].style.display = 'block';
            }
            oDivs[j].onmouseleave = function() {
                oImgs[this.index].style.display = 'none';
                oSpans[this.index].style.display = 'none';
            }
            oDivs[j].onclick = function() {
                if (this.className == '') {
                    for (var n = 0; n < oDivs.length; n++) {
                        if (n != this.index) {
                            oDivs[n].className = '';
                        }
                    }
                    this.className = 'checked';
                    i = this.index
                    oImg.src = imgList[i];
                }
            }
        }
    </script>
</body>

</html>